package Control;
import database.*;
import model.*;

import javax.imageio.ImageIO;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;


public class SalesReturnGUI extends JFrame implements ActionListener
{
	private JLabel jlID, jlQty, jlPrice, jlTotal, logoPicture;
	private JTextField jtID, jtQty, jtPrice, jtTotal;
	private JButton refund, cancel;
	private JPanel p1, p2, logo;
	private TableOperations to;

	public SalesReturnGUI()
	{
		setTitle("MDL - Sales Return");
        setSize(370, 400);
        setLocationRelativeTo(null);
        setResizable(true);
        setLayout(new GridLayout(3,1));
       
        GridBagLayout gridbagLayoutSettings = new GridBagLayout();
        GridBagConstraints gc = new GridBagConstraints();  
        Insets insets = new Insets(5,5,5,5);
        //to = new TableOperations();
        
        jtID = new JTextField(25);
        jtPrice = new JTextField(25);
        jtQty = new JTextField(25);
        jtTotal = new JPasswordField(25);
        
        BufferedImage myPicture = null;
        try
        {
                myPicture = ImageIO.read(new File("logo.png"));
        }
        catch (IOException e)
        {
                e.printStackTrace();
        }
        logo = new JPanel();
        logoPicture = new JLabel(new ImageIcon(myPicture));
        logo.add(logoPicture);
        this.add(logo);
        
        //Panel 1
        p1 = new JPanel();
        p1.setLayout(gridbagLayoutSettings);
        
        jlID = new JLabel("ID");
        gc.gridx = 0;    
        gc.gridy = 1;    
        gc.weighty = 0;    
        gc.weightx = 0;      
        gc.insets = insets;
        gc.fill = GridBagConstraints.BOTH;
        p1.add(jlID, gc);
        
     
        gc.gridx = 1;    
    	gc.gridy = 1;    
    	gc.weighty = 0;    
    	gc.weightx = 2;        
    	gc.insets = insets;
    	gc.fill = GridBagConstraints.BOTH;
        p1.add(jtID, gc);
        
        jlQty = new JLabel("Quantity");
        gc.gridx = 0;    
    	gc.gridy = 3;    
    	gc.weighty = 0;    
    	gc.weightx = 0;      
    	gc.insets = insets;
    	gc.fill = GridBagConstraints.BOTH;
        p1.add(jlQty, gc);
        
        
        gc.gridx = 1;    
    	gc.gridy = 3;    
    	gc.weighty = 0;    
    	gc.weightx = 2;        
    	gc.insets = insets;
    	gc.fill = GridBagConstraints.BOTH;
        p1.add(jtQty, gc);
        
        jlPrice = new JLabel("Price");
        gc.gridx = 0;    
    	gc.gridy = 5;    
    	gc.weighty = 0;    
    	gc.weightx = 0;      
    	gc.insets = insets;
    	gc.fill = GridBagConstraints.BOTH;
        p1.add(jlPrice, gc);
        
      
        gc.gridx = 1;    
    	gc.gridy = 5;    
    	gc.weighty = 0;    
    	gc.weightx = 2;        
    	gc.insets = insets;
    	gc.fill = GridBagConstraints.BOTH;
        p1.add(jtPrice, gc);
        
        jlTotal = new JLabel("Total");
        gc.gridx = 0;    
    	gc.gridy = 7;    
    	gc.weighty = 0;    
    	gc.weightx = 0;      
    	gc.insets = insets;
    	gc.fill = GridBagConstraints.BOTH;
        p1.add(jlTotal);
        
      
        gc.gridx = 1;    
    	gc.gridy = 7;    
    	gc.weighty = 0;    
    	gc.weightx = 2;        
    	gc.insets = insets;
    	gc.fill = GridBagConstraints.BOTH;
        p1.add(jtTotal);
        
        this.add(p1, BorderLayout.CENTER);
        
        //Panel 2
        p2 = new JPanel();
        p2.setLayout(gridbagLayoutSettings);
        
        refund = new JButton("Refund");
        gc.gridx = 1;    
        gc.gridy = 1;    
        gc.weighty = 0;    
        gc.weightx = 0;      
        gc.insets = insets;
        gc.fill = GridBagConstraints.BOTH;
        refund.addActionListener(this);
        p2.add(refund, gc);
        
        cancel = new JButton("Cancel");
        gc.gridx = 3;    
    	gc.gridy = 1;    
    	gc.weighty = 0;    
    	gc.weightx = 0;      
    	gc.insets = insets;
    	gc.fill = GridBagConstraints.BOTH;
        cancel = new JButton("Cancel");
        cancel.addActionListener(this);
        p2.add(cancel, gc);
	
        this.add(p2,BorderLayout.SOUTH);
	}


	public void actionPerformed(ActionEvent e) 
	{
		if(e.getSource() == cancel)
		{
			this.dispose();
		}
	}
	
	public static void main(String[] args) 
	{
		SalesReturnGUI s = new SalesReturnGUI();
		s.setVisible(true);
		
	}

}
